<?php
/**
 * CopyController.php class file.
 * @author wudg <544038230@qq.com>
 * @date 2020/11/10- 5:35 下午
 */

namespace console\controllers;


use console\components\daemons\copy\Daemon;
use yii\console\Controller;
use yii\console\ExitCode;

class CopyController extends Controller
{

    /**
     * 是否为守护进程模式运行
     * @var bool
     */
    public $daemon = false;

    /**
     * 启动复制异步任务
     * @return int
     */
    public function actionStart()
    {
        if(Daemon::start($this->daemon) === true)
        {
            return ExitCode::OK;
        }

        return ExitCode::UNSPECIFIED_ERROR;
    }



    public function options($actionID)
    {
        return array_merge(parent::options($actionID), ['daemon']);
    }

    /**
     * 关闭服务
     * @return int
     */
    public function actionStop()
    {
        Daemon::stop();

        return ExitCode::OK;
    }
}
